package IOStreamTest.FileStream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/*
Io流与Properties集合的联合使用
以.properties结尾的文件一般为属性配置文件
Properties是专门存放属性配置文件内容的类
 */
public class IoAndPropertiesTest {
    public static void main(String[] args) {
        FileInputStream fis = null;
        Properties map = new Properties();
        try {
            fis = new FileInputStream("src\\myFile.properties");
            //调用Properties中的load方法将文件中的数据加载到集合中
            map.load(fis);
            Set<Map.Entry<Object, Object>> set = map.entrySet();
            Iterator i = set.iterator();
            while(i.hasNext()){
                Object m = i.next();
                System.out.println(m);
            }
            System.out.println(map.size());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally{
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
